package com.sz.ac.handler;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.toolkit.StringUtils;

@Component
public class StatisticsSchedule 
{
	@Autowired
    private SchedulerFactoryBean schedulerFactoryBean;
	//统计时间设置
	@Value("${timeInvoke}")
    private String timeInvoke;
	private Logger logger = LoggerFactory.getLogger(StatisticsSchedule.class);
	public void scheduleJobs() throws SchedulerException 
	{
		
		if(StringUtils.isEmpty(timeInvoke))
		{
			logger.error("========your timer config is error===========");
			return ;
		}
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        startJob(scheduler,StatisticsJob.class,timeInvoke,"PayInvokeJob","PayInvokeJob_Grp");
//        startJob(scheduler,PayNotifyJob.class,timeNotify,"PayNotifyJob","PayNotifyJob_Grp");//与通联交互
//        startJob(scheduler,PayAccCheckJob.class,accCheck,"PayAccCheckJob","PayAccCheckJob_Grp");
    }
	
	private void startJob(Scheduler scheduler,Class<?> exeJobClass,String cronExpression,String jobName,String jobGroup) throws SchedulerException
	{
		JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) exeJobClass) .withIdentity(jobName,jobGroup).build(); 
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); 
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withSchedule(scheduleBuilder).build(); 
        scheduler.scheduleJob(jobDetail,cronTrigger); 
	}
	
}
